/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     ListNode *next;
 *     ListNode(int x) : val(x), next(NULL) {}
 * };
 */
class Solution {
public:
    ListNode* reverseList(ListNode* head) {
        if(head==NULL)return head;
        else{
            if(head->next==NULL)return head;
            
           ListNode *p1=head, *p2=head->next;
            p1->next=NULL;
            while(p2->next!=NULL){
                ListNode* t=p2;
                p2=p2->next;
                t->next=p1;
                p1=t;
            }
            p2->next=p1;
            return p2;
           

        }
    }
};
